# Retrieve the selected ID centroid
geo_df <- paste(params$region, params$df, sep = "_")
df_geo <- qs::qread(here("data", "geometry_export", paste0(geo_df, ".qs")))
id_sf <- df_geo$geometry[df_geo$ID == params$select_id]
map_loc <- as.vector(sf::st_coordinates(sf::st_centroid(id_sf)))

# Decide which color for the map
hexes <- c("#CA002095", "#F4A58295", "#A9A9A995", "#BAE4B395", "#31A35495")
map_col <- hexes[mean(sapply(params$title_card_data, `[[`, "hex_cat"))]
map_col_light <- gsub("95$", "20", map_col)

# Necessary for the mapdeck
map_token <- paste0("pk.eyJ1Ijoic3VzLW1jZ2lsbCIsImEiOiJjbDBxMTcyNWwyNTl0M2",
                    "RtZzRremNxOHA3In0.V2Ah5lxy-3RZlF2QKOvIjg")
options(rdeck.mapbox_access_token = map_token)
map_style_building <- "mapbox://styles/sus-mcgill/cl2bwtrsp000516rwyrkt9ior"

rdeck(map_style = map_style_building, initial_view_state = view_state(
    center = map_loc, zoom = params$map_zoom), width = "100%", height = "200px",
    controller = FALSE) |>
    add_mvt_layer(
        id = "study",
        data = mvt_url(paste0(params$mapbox_username, ".", geo_df)),
        pickable = FALSE,
        auto_highlight = FALSE,
        get_fill_color = scale_color_category(
            col = ID,
            palette = c(map_col_light, "#BAE4B300"),
            unmapped_color = "#BAE4B300",
            levels = c(params$select_id, "NA"),
            legend = FALSE),
        get_line_color = scale_color_category(
            col = ID,
            palette = c(map_col, "#BAE4B300"),
            unmapped_color = "#BAE4B300",
            levels = c(params$select_id, "NA"),
            legend = FALSE),
        line_width_units = "pixels",
        get_line_width = 5) |> suppressWarnings()

Air pollution

5% plus haut

L'aire de diffusion ranks in the top 5% en termes de niveau de pollution par le NO2. (NO2 = 17.1, données de 2016)

Vegetation

19% plus bas

L'aire de diffusion ranks in the bottom 1% in terms of vegetation (NDVI = 28%, data from 2019)

Sustainable transport

1% plus haut

81% des résidents utilisent les transports en commun, la marche ou le vélo pour se rendre au travail. L'aire de diffusion ranks in the top 1%. (Données de 2016)

Housing

1% plus bas

0% des logements occupés sont des maisons individuelles. L'aire de diffusion ranks in the bottom 1%. (Données de 2016)

Active living

7% plus haut

L'aire de diffusion ranks in the top 7% en termes de vie active. (Données de 2016)